package nuc.edu.tlias.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import nuc.edu.tlias.mapper.StudentMapper;
import nuc.edu.tlias.pojo.PageResult;
import nuc.edu.tlias.pojo.Student;
import nuc.edu.tlias.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    StudentMapper studentMapper;
    @Override
    public PageResult<Student> findall(String name, Integer degree, Integer clazzId, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);

        List<Student> list = studentMapper.findall(name,degree,clazzId);

        Page<Student> p = (Page<Student>) list;

        return new PageResult<Student>(p.getTotal(),p.getResult());
    }

    @Override
    public void delete(Integer[] ids) {
        studentMapper.delete(ids);
    }

    @Override
    public void save(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        student.setCreateTime(LocalDateTime.now());

        studentMapper.save(student);
    }

    @Override
    public Student getById(Integer id) {
        return studentMapper.getById(id);
    }

    @Override
    public void upload(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.upload(student);
    }

    @Override
    public void violation(Integer id, Integer score) {


        studentMapper.violation(id,score);
    }

}
